refactor(orgs): get organizations via GraphQL and display name instead login#347
refactor(orgs): get organizations via GraphQL and display name instead login#347lex111 wants to merge 5 commits into
Conversation
551ee53 to
2a92c3b
Compare
2a92c3b to
16c27ee
Compare
| return response.json().then(data => { | ||
| const orgs = []; | ||
|
|
||
| data.data.user.organizations.edges.reduce((key, item) => |
There was a problem hiding this comment.
Hey, I think that's not the best way of use reduce method, reduce returns something, this way you are just iterating over the array(similar what we do with forEach)
What do you think about this approach?
return data.data.user.organizations.edges
.map(item => item.node)
.sort((org1, org2) => org1.name > org2.name) There was a problem hiding this comment.
@jouderianjr I completely agree, thank you, I will fix it.
|
There remains such a problem: we need to open a link to reauthorize, in order for the user to update the token. How is this best done? |
|
|
||
| export async function fetchUserOrgs(user, accessToken) { | ||
| const ORGS_ENDPOINT = `${root}/users/${user}/orgs`; | ||
| const getOrganizationsQuery = ` |
There was a problem hiding this comment.
I'm a bit scared of seeing api/index.js grow too much. Would it be possible to put queries in entities subfolders ? This one for example would go in user/user.queries.js
There was a problem hiding this comment.
Highly agree, I made the mistake of laying things all down in api/index.js but it really makes sense to leverage feature api files (like we do with other parts of the app).
There was a problem hiding this comment.
What do you think about moving this query into something like
/src/queries/foo.query.js or something like that?
There was a problem hiding this comment.
Maybe it's better this way /src/api/queries/foo.query.js?
There was a problem hiding this comment.
What about /src/user/user.queries.js ? (just like we'll have user.api.js) ?
| style={styles.avatar} | ||
| source={{ | ||
| uri: user.avatar_url, | ||
| uri: imageUrl || user.avatar_url, |
There was a problem hiding this comment.
I think it's best to make the imageUrl prop mandatory and pass it as { user.avatar_url } where needed
There was a problem hiding this comment.
I do not think that it will turn out, i.e. when querying GraphQL, another notation is used (lowerCase instead of snake_case). We have already done this here.
There was a problem hiding this comment.
I still think that having an optional prop, magically provided by another prop in some cases, is a bit confusing. I'm in favor of "real dumb" presentation components.
Also in the spirit of #350 (did you check it?), I think GraphQL responses should be stored using the same schemas as REST responses in the entities array. That would enable us to access the data in the same way, regardless of where it came from (rest or graphql). Am I making sense? :/
There was a problem hiding this comment.
I have not watched, but probably this will solve the problem, it seems to me...
housseindjirdeh
left a comment
There was a problem hiding this comment.
I'm loving this @lex111, thank you. Left some discussion comments
| signIn = () => | ||
| openURLInView( | ||
| `https://github.com/login/oauth/authorize?response_type=token&client_id=${CLIENT_ID}&redirect_uri=gitpoint://welcome&scope=user%20repo&state=${stateRandom}` | ||
| `https://github.com/login/oauth/authorize?response_type=token&client_id=${CLIENT_ID}&redirect_uri=gitpoint://welcome&scope=user%20repo%20read:org&state=${stateRandom}` |
There was a problem hiding this comment.
Looks like this adds read access to org data. Without this, does your queries not work?
There was a problem hiding this comment.
Yes, without this, not getting an organization, there will be an error. Therefore, I write that there is a problem: we need to update the token when changing the scope, as for example in this case. And the question: how to do this?
|
|
||
| export async function fetchUserOrgs(user, accessToken) { | ||
| const ORGS_ENDPOINT = `${root}/users/${user}/orgs`; | ||
| const getOrganizationsQuery = ` |
There was a problem hiding this comment.
Highly agree, I made the mistake of laying things all down in api/index.js but it really makes sense to leverage feature api files (like we do with other parts of the app).
| id | ||
| login | ||
| name | ||
| avatarUrl |
There was a problem hiding this comment.
Seconding @machour's comment. I still don't know how exactly GraphQL works, but can we not stick to the same mention of avatar_url or does this version of the API just return it as avatarUrl instead of avatar_url?
There was a problem hiding this comment.
That's just the point, that the GraphQL query returns the keys in another notation
There was a problem hiding this comment.
FWIW I think you can make an alias to what you get from GQL. I'd prefer camelCase instead of snake_case though :P
|
@lex111 For your changed scope and the need to re-authorize, I think this call should help: |
| <WebView | ||
| source={{ | ||
| uri: `https://github.com/login/oauth/authorize?response_type=token&client_id=${CLIENT_ID}&redirect_uri=gitpoint://welcome&scope=user%20repo&state=${stateRandom}`, | ||
| uri: `https://github.com/login/oauth/authorize?response_type=token&client_id=${CLIENT_ID}&redirect_uri=gitpoint://welcome&scope=user%20repo%20read:org&state=${stateRandom}`, |
There was a problem hiding this comment.
Maybe for later but I think we can move this url into a constants files.
|
Closing this PR as it's superseded by the ongoing store refactoring. #272 remains open and will be dealt with. |
There are currently two requests when receiving organizations: one requests public organizations, another request also requests organizations with private membership. Using GraphQL, we can get all organizations with one query. However, doing so required updating the scope of the token. We need to somehow come up with a way to update the token, how to do it better, who has any ideas?
Also, within the framework of this PR done that, the organization name is output instead of the login, this closes #272